# -*- coding: utf-8 -*-
# @Time: 2021/11/26 20:35
# @Author: jiuwu
# @Email: 2359196586@qq.com
# @File: modelsMixin.py
# @Software: PyCharm
from django.db import models


class DateTimeModelsMixin(models.Model):
    """创建与修改时间拓展类"""
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    update_time = models.DateTimeField(verbose_name='修改时间', auto_now=True)

    class Meta:
        abstract = True  # 定义该类为抽象模型类，迁移时不会创建对应的表，只是用于拓展，让其他模型类来继承


class IsDeleteModelsMixin(models.Model):
    """逻辑删除拓展类"""
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    def delete(self, using=None, keep_parents=False):
        self.is_delete = True
        self.save()

    class Meta:
        abstract = True


class ModelsSetMixin(DateTimeModelsMixin, IsDeleteModelsMixin):
    """模型拓展整合类"""

    class Meta:
        abstract = True
